﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKArchMethodLibrary.Utils;
using YJKArchMethodLibrary.Utils.Generics;
using TopologySearch.LoopSearch;

namespace AreaEdit.AreaSet
{
	public class LoopSearcher
	{
		public LoopSearcher(ExternalCommandData commandData)
		{
			this.m_Revit = commandData;
		}

		public List<List<Curve>> GetBoundaryEdgeLoops(List<Pole> poleList, EdgePosition edgePos)
		{
			List<List<Curve>> result = new List<List<Curve>>();
			List<Pole> poleList2 = this.SegmentPoleList(poleList);
			List<Pole> poleList3 = this.FilterOverlapPoleList(poleList2);
			List<Node> theNodes = new List<Node>();
			this.InitData(poleList3, Node.SearchType._Anticlockwise, edgePos, ref theNodes);
			List<List<Pole>> outPoleList = new List<List<Pole>>();
			if (!this.SearchOuterBoundary(theNodes, ref outPoleList))
			{
				return result;
			}
			List<List<Pole>> outPoleList2 = new List<List<Pole>>();
			this.FormatPoleLoops(outPoleList, edgePos, true, ref outPoleList2);
			this.GetLoopCurves(outPoleList2, edgePos, ref result);
			return result;
		}

		public List<List<CurveInformationBean>> GetBoundaryEdgeBeanLoops(List<Pole> poleList, EdgePosition edgePos)
		{
			List<List<CurveInformationBean>> result = new List<List<CurveInformationBean>>();
			List<Pole> poleList2 = this.SegmentPoleList(poleList);
			List<Pole> poleList3 = this.FilterOverlapPoleList(poleList2);
			List<Node> theNodes = new List<Node>();
			this.InitData(poleList3, Node.SearchType._Anticlockwise, edgePos, ref theNodes);
			List<List<Pole>> outPoleList = new List<List<Pole>>();
			if (!this.SearchOuterBoundary(theNodes, ref outPoleList))
			{
				return result;
			}
			List<List<Pole>> outPoleList2 = new List<List<Pole>>();
			this.FormatPoleLoops(outPoleList, edgePos, true, ref outPoleList2);
			this.GetLoopCurves(outPoleList2, edgePos, ref result);
			return result;
		}

		public bool GetBoundaryPoles(List<Pole> poleList, EdgePosition edgePos, ref List<List<Pole>> poleLoops)
		{
			new List<List<Curve>>();
			List<Pole> poleList2 = this.SegmentPoleList(poleList);
			List<Pole> poleList3 = this.FilterOverlapPoleList(poleList2);
			List<Node> theNodes = new List<Node>();
			this.InitData(poleList3, Node.SearchType._Anticlockwise, edgePos, ref theNodes);
			List<List<Pole>> outPoleList = new List<List<Pole>>();
			if (!this.SearchOuterBoundary(theNodes, ref outPoleList))
			{
				return false;
			}
			List<List<Pole>> list = new List<List<Pole>>();
			this.FormatPoleLoops(outPoleList, edgePos, false, ref list);
			poleLoops = list;
			return true;
		}

		private List<Pole> SegmentPoleList(List<Pole> poleList)
		{
			List<Pole> list = new List<Pole>();
			List<List<XYZ>> list2 = new List<List<XYZ>>();
			List<Curve> list3 = new List<Curve>();
			int i = 0;
			while (i < poleList.Count)
			{
				Pole pole = poleList[i];
				XYZ xyz = XYZ.BasisZ;
				if (Geometry.LessThan(pole.Bulge, 0.0))
				{
					xyz = -xyz;
				}
				XYZ startPoint = pole.StartPoint;
				XYZ endPoint = pole.EndPoint;
				Curve item = null;
				try
				{
					if (pole.IsArcPole)
					{
						XYZ center = pole.Center;
						XYZ radianPnt = Geometry.CalculatMidPoint(startPoint, endPoint, center, xyz);
						item = this.m_Revit.Application.Application.CreatYJKArc(startPoint, endPoint, radianPnt);
					}
					else
					{
						item = YJKLineEx.YJKGetBound(startPoint, endPoint);
					}
				}
				catch (Exception)
				{
					poleList.RemoveAt(i);
					i--;
					goto IL_EC;
				}
				goto IL_B9;
				IL_EC:
				i++;
				continue;
				IL_B9:
				list3.Add(item);
				list2.Add(new List<XYZ>
				{
					pole.StartPoint,
					pole.EndPoint
				});
				goto IL_EC;
			}
			for (i = 0; i < list3.Count; i++)
			{
				Curve curve = list3[i];
				for (int j = i + 1; j < list3.Count; j++)
				{
					Curve curve2 = list3[j];
					IntersectionResultArray intersectionResultArray;
					SetComparisonResult setComparisonResult = curve.Intersect(curve2, out intersectionResultArray);
					if (setComparisonResult == SetComparisonResult.Overlap)
					{
						foreach (object obj in intersectionResultArray)
						{
							IntersectionResult intersectionResult = (IntersectionResult)obj;
							if (intersectionResult.XYZPoint != null)
							{
								list2[i].Add(intersectionResult.XYZPoint);
								list2[j].Add(intersectionResult.XYZPoint);
							}
						}
					}
				}
			}
			for (i = 0; i < poleList.Count; i++)
			{
				Pole pole2 = poleList[i];
				Curve curve3 = list3[i];
				List<XYZ> intersectPoints = list2[i];
				List<XYZ> list4 = TopologySearch.LoopSearch.Common.UniqueAndSortIntersectPoints(curve3, intersectPoints);
				if (list4.Count >= 2)
				{
					if (list4.Count == 2)
					{
						list.Add(pole2);
					}
					else
					{
						XYZ xyz2 = XYZ.BasisZ;
						if (Geometry.LessThan(pole2.Bulge, 0.0))
						{
							xyz2 = -xyz2;
						}
						double positiveHalfWidth = pole2.PositiveHalfWidth;
						double negativeHalfWidth = pole2.NegativeHalfWidth;
						XYZ center2 = pole2.Center;
						for (int k = 0; k < list4.Count - 1; k++)
						{
							XYZ xyz3 = list4[k];
							XYZ xyz4 = list4[k + 1];
							if (!Geometry.LessThan(xyz3.DistanceTo(xyz4), 0.032))
							{
								if (pole2.IsArcPole)
								{
									Pole item2 = Pole.NewPole(pole2.Element, pole2.UseRevitLinkInstance, xyz3, xyz4, center2, xyz2, positiveHalfWidth, negativeHalfWidth);
									list.Add(item2);
								}
								else
								{
									Pole item3 = Pole.NewPole(pole2.Element, pole2.UseRevitLinkInstance, xyz3, xyz4, positiveHalfWidth, negativeHalfWidth);
									list.Add(item3);
								}
							}
						}
					}
				}
			}
			return list;
		}

		private List<Pole> FilterOverlapPoleList(List<Pole> poleList)
		{
			List<Pole> list = new List<Pole>();
			for (int i = 0; i < poleList.Count; i++)
			{
				for (int j = i + 1; j < poleList.Count; j++)
				{
					Pole pole = poleList[i];
					Pole pole2 = poleList[j];
					if (pole.IsArcPole && pole2.IsArcPole)
					{
						XYZ xyz = null;
						XYZ xyz2 = null;
						Geometry.OverlapType overlapType = Geometry.IsOverlapOfTwoArc(pole.StartPoint, pole.EndPoint, pole.Center, pole2.StartPoint, pole2.EndPoint, pole2.Center, ref xyz, ref xyz2, 1E-09);
						if (overlapType == Geometry.OverlapType._OT_Equality || overlapType == Geometry.OverlapType._OT_FirstIncludeSecond)
						{
							poleList.RemoveAt(j);
							j--;
						}
						else if (overlapType == Geometry.OverlapType._OT_SecondIncludeFirst)
						{
							Pole value = poleList[i];
							poleList[i] = poleList[j];
							poleList[j] = value;
							poleList.RemoveAt(j);
							j--;
						}
					}
					else if (!pole.IsArcPole && !pole2.IsArcPole)
					{
						XYZ xyz3 = null;
						XYZ xyz4 = null;
						Geometry.OverlapType overlapType2 = Geometry.IsOverlapOfTwoLine(pole.StartPoint, pole.EndPoint, pole2.StartPoint, pole2.EndPoint, ref xyz3, ref xyz4, true, 1E-09);
						if (overlapType2 == Geometry.OverlapType._OT_Equality || overlapType2 == Geometry.OverlapType._OT_FirstIncludeSecond)
						{
							poleList.RemoveAt(j);
							j--;
						}
						else if (overlapType2 == Geometry.OverlapType._OT_SecondIncludeFirst)
						{
							Pole value2 = poleList[i];
							poleList[i] = poleList[j];
							poleList[j] = value2;
							poleList.RemoveAt(j);
							j--;
						}
					}
				}
			}
			return poleList;
		}

		private void InitData(List<Pole> poleList, Node.SearchType searchType, EdgePosition edgePos, ref List<Node> theNodes)
		{
			Dictionary<YJKArchMethodLibrary.Utils.KeyPoint, Node> dictionary = new Dictionary<YJKArchMethodLibrary.Utils.KeyPoint, Node>(new KeyPointComparer());
			for (int i = 0; i < poleList.Count; i++)
			{
				Pole pole = poleList[i];
				XYZ ptNodePosition = pole.StartPoint;
				this.InitNode(ptNodePosition, pole, true, ref dictionary);
				ptNodePosition = pole.EndPoint;
				this.InitNode(ptNodePosition, pole, false, ref dictionary);
			}
			foreach (KeyValuePair<YJKArchMethodLibrary.Utils.KeyPoint, Node> keyValuePair in dictionary)
			{
				if (searchType == Node.SearchType._Anticlockwise)
				{
					keyValuePair.Value.AnticlockwiseSortElements();
				}
				else
				{
					keyValuePair.Value.ClockwiseSortElements();
				}
				theNodes.Add(keyValuePair.Value);
			}
		}

		private void InitNode(XYZ ptNodePosition, Pole pole, bool isStart, ref Dictionary<YJKArchMethodLibrary.Utils.KeyPoint, Node> the2DGraph)
		{
			YJKArchMethodLibrary.Utils.KeyPoint key = this.ConvertToKeyPoint(ptNodePosition);
			if (!the2DGraph.ContainsKey(key))
			{
				Node value = new Node(ptNodePosition, new List<Pole>
				{
					pole
				});
				the2DGraph.Add(key, value);
				return;
			}
			Node node = the2DGraph[key];
			if (!ptNodePosition.IsAlmostEqualTo(node.Position))
			{
				if (isStart)
				{
					pole.StartPoint = node.Position;
				}
				else
				{
					pole.EndPoint = node.Position;
				}
			}
			node.AddPole(pole);
		}

		private YJKArchMethodLibrary.Utils.KeyPoint ConvertToKeyPoint(XYZ pt)
		{
			return new YJKArchMethodLibrary.Utils.KeyPoint(pt.X, pt.Y, pt.Z);
		}

		private void TrimAllNode(ref List<Node> theNodes)
		{
			foreach (Node node in theNodes)
			{
				int count = node.PoleList.Count;
				if (count != 1)
				{
					node.AnticlockwiseSortElements();
					List<Pole> poleList = node.PoleList;
					for (int i = 0; i < count; i++)
					{
						int index = i;
						int index2 = i + 1;
						if (i == count - 1)
						{
							index2 = 0;
						}
						Pole pole = poleList[index];
						Pole pole2 = poleList[index2];
						double dSAngle = 0.0;
						double dEAngle = 0.0;
						pole.GetAngle(node.Position, ref dSAngle);
						pole2.GetAngle(node.Position, ref dEAngle);
						double val = Geometry.BetweenTheAngles(dSAngle, dEAngle, true);
						if (!Geometry.IsEqual(val, Math.PI))
						{
							this.TrimPoleSideline(node.Position, ref pole, ref pole2);
						}
					}
				}
			}
		}

		private bool TrimPoleSideline(XYZ position, ref Pole pole1, ref Pole pole2)
		{
			Curve curve = null;
			XYZ xyz = pole1.CurNegativeStartPoint(position);
			XYZ xyz2 = pole1.CurNegativeEndPoint(position);
			if (pole1.IsArcPole)
			{
				XYZ center = pole1.Center;
				XYZ xyz3 = XYZ.BasisZ;
				if (Geometry.LessThan(pole1.Bulge, 0.0))
				{
					xyz3 = -xyz3;
				}
				XYZ radianPnt = Geometry.CalculatMidPoint(xyz, xyz2, center, xyz3);
				try
				{
					curve = this.m_Revit.Application.Application.CreatYJKArc(xyz, xyz2, radianPnt);
					goto IL_90;
				}
				catch (Exception)
				{
					return false;
				}
			}
			try
			{
				curve = YJKLineEx.YJKGetBound(xyz, xyz2);
			}
			catch (Exception)
			{
				return false;
			}
			IL_90:
			Curve curve2 = null;
			XYZ xyz4 = pole2.CurPositiveStartPoint(position);
			XYZ xyz5 = pole2.CurPositiveEndPoint(position);
			if (pole2.IsArcPole)
			{
				XYZ center2 = pole2.Center;
				XYZ xyz6 = XYZ.BasisZ;
				if (Geometry.LessThan(pole2.Bulge, 0.0))
				{
					xyz6 = -xyz6;
				}
				XYZ radianPnt2 = Geometry.CalculatMidPoint(xyz4, xyz5, center2, xyz6);
				try
				{
					curve2 = this.m_Revit.Application.Application.CreatYJKArc(xyz4, xyz5, radianPnt2);
					goto IL_127;
				}
				catch (Exception)
				{
					return false;
				}
			}
			try
			{
				curve2 = YJKLineEx.YJKGetBound(xyz4, xyz5);
			}
			catch (Exception)
			{
				return false;
			}
			IL_127:
			XYZ xyz7 = Geometry.IntersectWithTwoCurves(curve, curve2, position, true, true, this.m_Revit.Application.Application);
			if (xyz7 != null)
			{
				pole1.SetCurNegativeStartPoint(position, xyz7);
				pole2.SetCurPositiveStartPoint(position, xyz7);
			}
			return true;
		}

		private bool SearchOuterBoundary(List<Node> theNodes, ref List<List<Pole>> outPoleList)
		{
			int num = -1;
			int num2 = 0;
			int num3 = 0;
			int num4 = theNodes.Count * 4;
			bool isFirstPt = true;
			List<XYZ> list = new List<XYZ>();
			List<double> list2 = new List<double>();
			List<Pole> list3 = new List<Pole>();
			Node node = null;
			Node prevNode = null;
			while (theNodes.Count > 1 && num2 < 2 && num3 < num4)
			{
				if (num == -1 || num == 1)
				{
					list = new List<XYZ>();
					list2 = new List<double>();
					list3 = new List<Pole>();
					Node leftBottomNode = this.GetLeftBottomNode(theNodes);
					if (leftBottomNode == null)
					{
						return false;
					}
					node = leftBottomNode;
					list.Add(node.Position);
					num3++;
					prevNode = null;
					isFirstPt = true;
				}
				Pole pole = null;
				Node nextNode = this.GetNextNode(isFirstPt, prevNode, node, theNodes, Node.SearchType._Anticlockwise, ref pole);
				if (nextNode != null)
				{
					double item = pole.CurBulge(node.Position);
					list2.Add(item);
					list3.Add(pole);
					prevNode = node;
					isFirstPt = false;
					node = nextNode;
					list.Add(node.Position);
					num3++;
					if (this.IsClosed(list))
					{
						double item2 = pole.CurBulge(node.Position);
						list2.Add(item2);
						if (list.Count > 1)
						{
							outPoleList.Add(list3);
						}
						this.DeleteNodeInClosedSpace(ref theNodes, list, list2);
						num = 1;
					}
					else
					{
						num = 0;
					}
					num2 = 0;
				}
				else
				{
					prevNode = null;
					isFirstPt = true;
					num2++;
					if (num2 == 2 && list.Count > 1)
					{
						outPoleList.Add(list3);
					}
				}
			}
			return true;
		}

		private Node GetLeftBottomNode(List<Node> theNodes)
		{
			XYZ xyz = theNodes[0].Position;
			Node result = null;
			foreach (Node node in theNodes)
			{
				XYZ position = node.Position;
				if (position.IsAlmostEqualTo(xyz, 0.032))
				{
					result = node;
				}
				else if (this.CompareXYLess(position, xyz))
				{
					xyz = position;
					result = node;
				}
			}
			return result;
		}

		private bool CompareXYLess(XYZ lhv, XYZ rhv)
		{
			if (Geometry.IsEqual(lhv.Y, rhv.Y))
			{
				if (Geometry.LessThan(lhv.X, rhv.X))
				{
					return true;
				}
			}
			else if (Geometry.LessThan(lhv.Y, rhv.Y))
			{
				return true;
			}
			return false;
		}

		private Node GetNextNode(bool isFirstPt, Node PrevNode, Node CurNode, List<Node> theNodes, Node.SearchType searchType, ref Pole nextEdge)
		{
			Node result = null;
			if (isFirstPt)
			{
				List<Pole> poleList = CurNode.PoleList;
				double referenceStartAngle = 3.1416926535897933;
				poleList.Sort(new YJKArchMethodLibrary.Utils.AngleComparer(CurNode.Position, referenceStartAngle));
				int i = 0;
				int num = 0;
				while (i < poleList.Count)
				{
					Pole pole = poleList[i];
					int num2 = 0;
					pole.GetWinding(CurNode.Position, ref num2);
					if (num2 != -1)
					{
						break;
					}
					double val = 0.0;
					pole.GetAngle(CurNode.Position, ref val);
					if (!Geometry.GreaterThan(val, Math.PI) || !Geometry.Lessthan_Or_Equal(val, 4.71238898038469))
					{
						break;
					}
					num++;
					i++;
				}
				int num3 = 0;
				if (num > 0)
				{
					num3 += num;
					if (num == poleList.Count)
					{
						num3--;
					}
				}
				nextEdge = poleList[num3];
				nextEdge.SetIsPositiveDirection(CurNode.Position);
				XYZ pos = nextEdge.CurEndPoint(CurNode.Position);
				result = this.FindNodeByPos(theNodes, pos);
			}
			else
			{
				int num4 = CurNode.FindLinkPoleWithOtherNode(PrevNode.Position, searchType);
				if (num4 != -1)
				{
					num4++;
					if (num4 == CurNode.PoleList.Count)
					{
						num4 = 0;
					}
					nextEdge = CurNode.PoleList[num4];
					nextEdge.SetIsPositiveDirection(CurNode.Position);
					XYZ pos2 = nextEdge.CurEndPoint(CurNode.Position);
					result = this.FindNodeByPos(theNodes, pos2);
				}
			}
			return result;
		}

		private Node FindNodeByPos(List<Node> theNodes, XYZ pos)
		{
			foreach (Node node in theNodes)
			{
				if (this.IsAlmostEqualTo(pos, node.Position, 0.032))
				{
					return node;
				}
			}
			return null;
		}

		private bool IsAlmostEqualTo(UV pt1, UV pt2, double eps)
		{
			double val = pt1.DistanceTo(pt2);
			return Geometry.LessThan(val, eps);
		}

		private bool IsAlmostEqualTo(XYZ pt1, XYZ pt2, double eps)
		{
			double val = pt1.DistanceTo(pt2);
			return Geometry.LessThan(val, eps);
		}

		private bool IsClosed(List<XYZ> BorderPos)
		{
			if (BorderPos.Count < 2)
			{
				return false;
			}
			XYZ pt = BorderPos[0];
			XYZ pt2 = BorderPos[BorderPos.Count - 1];
			return this.IsAlmostEqualTo(pt, pt2, 0.032);
		}

		private void DeleteNodeInClosedSpace(ref List<Node> theNodes, List<XYZ> points, List<double> bulges)
		{
			List<List<XYZ>> list = new List<List<XYZ>>();
			List<List<double>> list2 = new List<List<double>>();
			List<EdgeInfo> list3 = new List<EdgeInfo>();
			Geometry.ConvertToSimpleClosedPolylineAndSimpleCurve(points, bulges, ref list, ref list2, ref list3);
			List<List<XYZ>> list4 = new List<List<XYZ>>();
			for (int i = 0; i < list.Count; i++)
			{
				List<XYZ> item = new List<XYZ>();
				if (Geometry.GetFittingPolyline(list[i], list2[i], ref item, AssistFunc.mmToFeet(200.0)))
				{
					list4.Add(item);
				}
			}
			List<int> list5 = new List<int>();
			List<UV> list6 = new List<UV>();
			for (int i = 0; i < theNodes.Count; i++)
			{
				XYZ position = theNodes[i].Position;
				bool flag = false;
				for (int j = 0; j < list3.Count; j++)
				{
					EdgeInfo edgeInfo = list3[j];
					if (!this.IsAlmostEqualTo(edgeInfo.StartPoint, edgeInfo.EndPoint, 0.032))
					{
						if (edgeInfo.IsArc)
						{
							XYZ ptCenterOfArc = null;
							Geometry.GetCenterWithBulge(edgeInfo.StartPoint, edgeInfo.EndPoint, edgeInfo.Bulge, ref ptCenterOfArc);
							XYZ xyz = XYZ.BasisZ;
							if (Geometry.LessThan(edgeInfo.Bulge, 0.0))
							{
								xyz = -xyz;
							}
							if (Geometry.Is_Point_OnSegment(edgeInfo.StartPoint, edgeInfo.EndPoint, ptCenterOfArc, xyz, position, 1E-09))
							{
								list5.Add(i);
								list6.Add(new UV(position.X, position.Y));
								flag = true;
								break;
							}
						}
						else if (Geometry.Is_Point_OnSegment(edgeInfo.StartPoint, edgeInfo.EndPoint, position, 1E-09))
						{
							list5.Add(i);
							list6.Add(new UV(position.X, position.Y));
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					for (int j = 0; j < list4.Count; j++)
					{
						int num = Geometry.PointInPloygon(list4[j], position, 0.0001, 0.0001);
						if (num != -1)
						{
							list5.Add(i);
							list6.Add(new UV(position.X, position.Y));
							break;
						}
					}
				}
			}
			List<int> list7 = new List<int>();
			for (int i = 0; i < list6.Count; i++)
			{
				int num2 = list5[i];
				Node node = theNodes[num2];
				List<Pole> poleList = node.PoleList;
				XYZ position2 = node.Position;
				int k = 0;
				while (k < poleList.Count)
				{
					Pole pole = poleList[k];
					XYZ xyz2 = pole.CurEndPoint(position2);
					UV pt2d = new UV(xyz2.X, xyz2.Y);
					int num3 = list6.FindIndex((UV s) => this.IsAlmostEqualTo(s, pt2d, 0.032));
					if (num3 == -1)
					{
						k++;
					}
					else
					{
						Node node2 = this.FindNodeByPos(theNodes, xyz2);
						if (node2 == null)
						{
							k++;
						}
						else
						{
							poleList.RemoveAt(k);
							num3 = node2.FindLinkPoleWithOtherNode(position2, Node.SearchType._Clockwise);
							if (num3 != -1)
							{
								node2.RemoveEdge(num3);
							}
						}
					}
				}
				if (poleList.Count == 0)
				{
					list7.Add(num2);
				}
				else
				{
					node.AnticlockwiseSortElements();
				}
			}
			for (int i = list7.Count - 1; i >= 0; i--)
			{
				theNodes.RemoveAt(list7[i]);
			}
		}

		private void FormatPoleLoops(List<List<Pole>> outPoleList, EdgePosition edgePos, bool isTrimAllNode, ref List<List<Pole>> formatPoleLoops)
		{
			for (int i = 0; i < outPoleList.Count; i++)
			{
				List<Pole> list = outPoleList[i];
				for (int j = 0; j < list.Count - 1; j++)
				{
					Pole pole = list[j];
					int num = list.FindIndex(j + 1, (Pole s) => s == pole);
					if (num >= 0 && num != j)
					{
						List<Pole> range = list.GetRange(0, j);
						List<Pole> range2 = list.GetRange(j + 1, num - j - 1);
						List<Pole> collection = new List<Pole>();
						if (num < list.Count - 1)
						{
							collection = list.GetRange(num + 1, list.Count - (num + 1));
						}
						range.AddRange(collection);
						if (range.Count > 1)
						{
							outPoleList.Add(range);
						}
						if (range2.Count > 1)
						{
							outPoleList.Add(range2);
						}
						outPoleList.RemoveAt(i);
						i--;
						break;
					}
				}
			}
			List<Pole> list2 = new List<Pole>();
			foreach (List<Pole> list3 in outPoleList)
			{
				formatPoleLoops.Add(list3);
				list2.AddRange(list3);
			}
			if (isTrimAllNode)
			{
				List<Node> list4 = new List<Node>();
				this.InitData(list2, Node.SearchType._Anticlockwise, edgePos, ref list4);
				this.TrimAllNode(ref list4);
			}
		}

		private void GetLoopCurves(List<List<Pole>> outPoleList, EdgePosition edgePos, ref List<List<CurveInformationBean>> edgeLoops)
		{
			foreach (List<Pole> list in outPoleList)
			{
				List<CurveInformationBean> list2 = new List<CurveInformationBean>();
				foreach (Pole pole in list)
				{
					XYZ xyz = XYZ.BasisZ;
					XYZ xyz2;
					XYZ xyz3;
					if (edgePos == EdgePosition.EP_Center)
					{
						xyz2 = pole.StartPoint;
						xyz3 = pole.EndPoint;
					}
					else if (edgePos == EdgePosition.EP_Outside)
					{
						if (pole.IsPositiveDirection)
						{
							xyz2 = pole.PositiveStartPoint;
							xyz3 = pole.PositiveEndPoint;
						}
						else
						{
							xyz2 = pole.NegativeEndPoint;
							xyz3 = pole.NegativeStartPoint;
							xyz = -xyz;
						}
					}
					else if (pole.IsPositiveDirection)
					{
						xyz2 = pole.NegativeEndPoint;
						xyz3 = pole.NegativeStartPoint;
						xyz = -xyz;
					}
					else
					{
						xyz2 = pole.PositiveStartPoint;
						xyz3 = pole.PositiveEndPoint;
					}
					Curve inputCurve = null;
					try
					{
						if (pole.IsArcPole)
						{
							XYZ center = pole.Center;
							XYZ radianPnt = Geometry.CalculatMidPoint(xyz2, xyz3, center, xyz);
							inputCurve = this.m_Revit.Application.Application.CreatYJKArc(xyz2, xyz3, radianPnt);
						}
						else
						{
							inputCurve = YJKLineEx.YJKGetBound(xyz2, xyz3);
						}
					}
					catch (Exception)
					{
						continue;
					}
					list2.Add(new CurveInformationBean(inputCurve, pole.Element, pole.UseRevitLinkInstance));
				}
				edgeLoops.Add(list2);
			}
		}

		private void GetLoopCurves(List<List<Pole>> outPoleList, EdgePosition edgePos, ref List<List<Curve>> edgeLoops)
		{
			foreach (List<Pole> list in outPoleList)
			{
				List<Curve> list2 = new List<Curve>();
				foreach (Pole pole in list)
				{
					XYZ xyz = XYZ.BasisZ;
					XYZ xyz2;
					XYZ xyz3;
					if (edgePos == EdgePosition.EP_Center)
					{
						xyz2 = pole.StartPoint;
						xyz3 = pole.EndPoint;
					}
					else if (edgePos == EdgePosition.EP_Outside)
					{
						if (pole.IsPositiveDirection)
						{
							xyz2 = pole.PositiveStartPoint;
							xyz3 = pole.PositiveEndPoint;
						}
						else
						{
							xyz2 = pole.NegativeEndPoint;
							xyz3 = pole.NegativeStartPoint;
							xyz = -xyz;
						}
					}
					else if (pole.IsPositiveDirection)
					{
						xyz2 = pole.NegativeEndPoint;
						xyz3 = pole.NegativeStartPoint;
						xyz = -xyz;
					}
					else
					{
						xyz2 = pole.PositiveStartPoint;
						xyz3 = pole.PositiveEndPoint;
					}
					Curve item = null;
					try
					{
						if (pole.IsArcPole)
						{
							XYZ center = pole.Center;
							XYZ radianPnt = Geometry.CalculatMidPoint(xyz2, xyz3, center, xyz);
							item = this.m_Revit.Application.Application.CreatYJKArc(xyz2, xyz3, radianPnt);
						}
						else
						{
							item = YJKLineEx.YJKGetBound(xyz2, xyz3);
						}
					}
					catch (Exception)
					{
						continue;
					}
					list2.Add(item);
				}
				edgeLoops.Add(list2);
			}
		}

		private ExternalCommandData m_Revit;
	}
}
